package com.freewater.springboot.demo.ioc.beanmethodinheritance;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig implements ConfigA, ConfigB {

    // 多个@Bean方法都返回的是名字为"beanC"的Bean，但是他们的依赖数量不同（参数个数不同）
    // Spring 会选择参数多的那个@Bean方法，即方法：BeanC beanC(BeanA, BeanB)，来生成beanC

    @Bean
    public BeanC beanC(BeanA beanA) {
        System.out.println("beanC1");
        return new BeanC(beanA);
    }

    @Bean
    public BeanC beanC(BeanB beanB) {
        System.out.println("beanC2");
        return new BeanC(beanB);
    }

    @Bean
    public BeanC beanC(BeanA beanA, BeanB beanB) {
        System.out.println("beanC3");
        return new BeanC(beanA, beanB);
    }
}
